package com.mls.fivedistrict.server.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.github.pagehelper.PageHelper;
import com.mls.fivedistrict.pojo.News;
import com.mls.fivedistrict.pojo.NewsNewsTag;
import com.mls.fivedistrict.dao.NewsNewsTagMapper;
import com.mls.fivedistrict.server.NewsNewsTagService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 新闻标签的关系表 服务实现类
 * </p>
 *
 * @author Five Team
 * @since 2018-06-28
 */
@Service
public class NewsNewsTagServiceImpl extends ServiceImpl<NewsNewsTagMapper, NewsNewsTag> implements NewsNewsTagService {

    @Override
    public List getNewsByRecommend(Long newsId) {
        Wrapper wrapper = Condition.create();
        wrapper.eq("news_id", newsId);
        List<NewsNewsTag> list = selectList(wrapper);
        List<Long> tagList = new ArrayList<>();
        for (NewsNewsTag newsNewsTag : list) {
            tagList.add(newsNewsTag.getNewsTagId());
        }
        Wrapper recommendWrapper = Condition.create();
        recommendWrapper.ne("news_id", newsId);
        recommendWrapper.in("news_tag_id", tagList);
        recommendWrapper.groupBy("news_id");
        PageHelper.startPage(1, 3);
        List recommendList = selectList(recommendWrapper);
        return recommendList;
    }
}
